# mc_integral1.R
# Calculating a definite integral using the Monte Carlo method

# Exemplo de utilizacao:
# source('mc_integral1.R')
# mc_integral(sin, 0, pi)

# Rizzo pag 125

mc_integrate <- function(g, a, b, m=100000)
{
	# 1. Generate X1,...,Xm iid from Uniform(a,b)
	X <- runif(m, a, b)

	# 2. Compute E(g(X))=1/m . g(Xi)
	g. <- sum(g(X)/m)

	# 3. O = (b-a) . E(g(X))
	(b-a) * g.
}

# Rizzo pag 127
# m = var^2 / e^2

# FIXME: broken


